#!/usr/bin/env python3
#
# @file Utils.py
# @brief
# @author QRS
# @version 1.0
# @date 2024-04-02 22:27


import logging
from enum import Enum


class ErrorCode(Enum):
    NO_ERROR = 0
    WSS_CAM_NOTDETECT = 1101
    MV_CC_ENUMDEVICES = 2001
    MV_CC_CREATEHANDLE = 2002
    MV_CC_OPENDEVICE = 2003
    MV_CC_STARTGRABBING = 2004
    MV_CC_STOPGRABBING = 2005,
    MV_CC_CLOSEDEVICE = 2006,
    MV_CC_DESTROYHANDLE = 2007,
    MV_SET_TRIGGERMODE = 2101
    MV_GET_PAYLOADSIZE = 2102
    UNKNOWN_ERROR = 9999


class WSSError(Exception):
    def __init__(self, errcode, message):
        self.errcode = errcode
        self.message = message
        super().__init__(f'Error[{self.errcode}]: {self.message}')


class Logger(object):
    isInit = False

    @classmethod
    def init(cls):
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
            datefmt='%Y-%m-%d %H:%M:%S',
            handlers=[ logging.StreamHandler() ]
        )
        cls.isInit = True

    @classmethod
    def info(cls, message):
        if not cls.isInit:
            cls.init()
        logging.info(f'{message}')

    @classmethod
    def warn(cls, message):
        if not cls.isInit:
            cls.init()
        logging.warning(f'{message}')

    @classmethod
    def error(cls, message):
        if not cls.isInit:
            cls.init()
        logging.error(f'{message}')
